$(function(){
	$("#ExamArrangementSearch").bind('click',function(){
		var ExamArrangementName=$('#ExamArrangementName').val();
		alert(ExamArrangementName);
		$("#ExamArrangement").datagrid('load','../exam2/ExamArrangementSearch?ExamArrangementName='+ExamArrangementName);
	})
	$('#eaStartTime').datetimebox({
	    required:true
	});
	$('#eaEndTime').datetimebox({
	    required:true
	});
	$('#examAN').textbox({
		required:true
	})
	$('#examP').textbox({
		required:true
	})
	$('#eaState').textbox({
		required:true
	})
	
	$('#AllScore').textbox({
		required:true
	})
	
	$('#snum').textbox({
		required:true
	})
	
	$('#ss').textbox({
		required:true
	})
	$('#mnum').textbox({
		required:true
	})
	
	$('#ms').textbox({
		required:true
	})
	$('#jnum').textbox({
		required:true
	})
	
	$('#js').textbox({
		required:true
	})
	$('#fnum').textbox({
		required:true
	})
	
	$('#fs').textbox({
		required:true
	})
	var url='../exam2/getAllExamArrangement';
	$('#ExamArrangement').datagrid({
	    url:url,
	    columns:[[
	    	{field:'examArrangementId',title:"编号",width:50,align:'center'},
			{field:'examArrangementName',title:"考试安排名称",width:150,align:'center'},
			{field:'exam_paper_id',title:"试卷名称",width:150,align:'center',
	    		formatter: function(value,row,index){
					if (row.examPaper){
						return row.examPaper.examPaperName;
					} else {
						return value;
					}
				}},
			{field:'startTime',title:"开始时间",width:150,align:'center'},
			{field:'endTime',title:"结束时间",width:150,align:'center'},
			{field:'examineeNum',title:"考生数",width:80,align:'center'},
			{field:'examinationRoomState',title:"考场状态",width:80,align:'center'},
			{field:'',width:100,align:'center',checkbox:true}
	    ]],
		fit:true,
		method:'get',
		toolbar:'#ExamArrangement_tb',
		rownumbers:true,
		width: 700,
		height: 250,
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:3,
		//可选的每页大小
		pageList:[3,6,10],
		
		});
	
	
	// 定义底部保存，清空，取消按钮
	$('#ExamArrangementAdd').dialog({
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				$('#ffexamarrange').form('submit', {
					onSubmit : function(param) {
						var examArrangementId=$("#examArrangementId").val();
						if(examArrangementId==null||examArrangementId==""){
							$.post("../exam2/ExamArrangeAdd?examAN="+$("#examAN").val()+"&examP="+$("#examP").val()+"&eaStartTime="+$("#eaStartTime").val()+"&eaEndTime="+$("#eaEndTime").val()
									+"&AllScore="+$("#AllScore").val()+"&snum="+$("#snum").val()+"&ss="+$("#ss").val()
									+"&mnum="+$("#mnum").val()+"&ms="+$("#ms").val()
									+"&jnum="+$("#jnum").val()+"&js="+$("#js").val()
									+"&fnum="+$("#fnum").val()+"&fs="+$("#fs").val()
									,
									function(){
								$('#ExamArrangement').datagrid('reload');
							})
						}else{
							var rows = $('#ExamArrangement').datagrid('getSelected');
							var examPaperId=rows.examPaper.examPaperId;
							$.post("../exam2/ExamArrangeUpdata?examAN="+$("#examAN").val()+"&examP="+$("#examP").val()+"&eaStartTime="+$("#eaStartTime").val()+"&eaEndTime="+$("#eaEndTime").val()+"&examArrangementId="+$("#examArrangementId").val()+"&examPaperId="+examPaperId
									/*+"&AllScore="+$("#AllScore").val()+"&snum="+$("#snum").val()+"&ss="+$("#ss").val()
									+"&mnum="+$("#mnum").val()+"&ms="+$("#ms").val()
									+"&jnum="+$("#jnum").val()+"&js="+$("#js").val()
									+"&fnum="+$("#fnum").val()+"&fs="+$("#fs").val()*/
									,
									function(){
								$('#examArrangementId').val("");
								$('#examAN').textbox('setValue',"");
								$('#examP').textbox('setValue',"");
								/*$("#AllScore").textbox('setValue',"");
								
								$("#AllScore").textbox('setValue',"");$("#snum").textbox('setValue',"");
								$("#ss").textbox('setValue',"");$("#mnum").textbox('setValue',"");
								$("#ms").textbox('setValue',"");$("#jnum").textbox('setValue',"");
								$("#js").textbox('setValue',"");$("#fnum").textbox('setValue',"");
								$("#fs").textbox('setValue',"");*/
								
								$('#eaStartTime').datetimebox('setValue',"");
								$('#eaEndTime').datetimebox('setValue',"");
								$('#ExamArrangement').datagrid('reload');
							})
						}
						$("#ExamArrangementAdd").window("close");
					},
					success : function(data) {
					}
				});

			}
		}, {
			text : '清空',
			iconCls : 'icon-clear',
			handler : function() {
				$('#ffexamarrange').form('clear');
			}
		}, {
			text : '取消',
			iconCls : 'icon-cancel',
			handler : function() {
				$("#ExamArrangementAdd").window("close");
			}
		} ]
	});
});
//添加
function add(){
	$("#ExamArrangementAdd").window("open");
}
//修改
function edit(){
	var rows = $('#ExamArrangement').datagrid('getSelected');
	$('#examArrangementId').val(rows.examArrangementId);
	$('#examAN').textbox('setValue',rows.examArrangementName);
	$('#examP').textbox('setValue',rows.examPaper.examPaperName);
	$('#eaStartTime').datetimebox('setValue',rows.startTime);
	$('#eaEndTime').datetimebox('setValue',rows.endTime);
	$("#ExamArrangementAdd").window("open");
}
//删除
function remove(){
	var rows = $('#ExamArrangement').datagrid('getSelections');
	if(rows.length > 0){
		$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
			if(r){
				var ExamArrangementIds = [];
				var ExamPaperIds=[];
				for(var i = 0; i < rows.length; i++){
					debugger;
					ExamArrangementIds.push(rows[i].examArrangementId);
					ExamPaperIds.push(rows[i].examPaper.examPaperId);
					
				}
				alert(ExamArrangementIds+ExamPaperIds);
				$.post('../exam2/deleteExamArrangement?value='+ExamArrangementIds+'&value1='+ExamPaperIds,function(){
					$('#ExamArrangement').datagrid('reload');
				})
				wjl_editIndex = undefined;
			}
		})
	}else{
		$.messager.alert('提示','请选择要删除的记录！','error');
	}
}